package com.way.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.way.domain.mall.Order;
import com.way.exception.CommonException;
import com.way.mapper.OrderMapper;
import com.way.service.IOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderService implements IOrderService {

    private static final Logger LOG = LoggerFactory.getLogger(IOrderService.class);

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void saveOrder(Order order) {

        orderMapper.saveOrder(order);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrder(List<Order> orderList) {
        try {
            for (Order order: orderList) {
                orderMapper.saveOrder(order);
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(),e);
            throw new CommonException(e.getMessage());
        }
    }

    @Override
    public List<Order> getOrder(Order order) {
        return orderMapper.selectList(new QueryWrapper<>(order));
        //return orderMapper.getOrderList(order);
    }

    @Override
    public Order getOrder(int orderId) {
        return orderMapper.getOrder(orderId);
    }
}
